#pragma once

#include "_include/header.hpp"

struct RobtConfigs {
    // string CQAPPDIR;
    int64_t ROBOTQQCODE, ROBOTADMIN;
    std::set<int64_t> PSEUDOADMINS, MANGROUPS;
} RCFG = {NULL};

#define DTQCODE 1004004153

void robotinit() {
    using namespace cq;
    using namespace std;

    using json = nlohmann::json;

    /*加载配置文件*/

    string rcfp = utils::ansi(get_app_directory() + "config.json");
    ifstream file(rcfp);

    if (!file.good()) {
        /*构建*/

        ofstream newfile(rcfp);

        json j;
        j["mangroups"] = {0, 0, 0};
        j["robotadmin"] = 0;
        j["pseudoadmns"] = {0};

        newfile << j.dump(4);

        newfile.close();


        //newfile << string("/*JSON VERSION 0.0.1*/ \n\n");
        //newfile << R"({)" + string("\n\t/*唯一插件管理者*/\n\t");
        //newfile << R"("robotadmin": 1,)" + string("\n\n\t/*托管群列表*/\n\t");
        //newfile << R"("mangroups": [)" + string("\n\t\t1,\n\t\t2,\n\t\t3\n\t],\n\n\t");
        //newfile << R"(/*伪管理员列表*/)" + string("\n\t\"pseudoadmns\":[]\n}");
        //newfile.close();

    } else {
        file.seekg(0, ios::end);
        int lenth = (int)file.tellg();
        file.seekg(0, ios_base::beg);
        char *buffer = new char[lenth]{0};
        file.read(buffer, lenth);
        file.close();

        string configdata(buffer);

        send_private_message(DTQCODE, configdata);

        ; // json解析处理
    }
}